import Vue from 'vue';
import messageBox from './message-box.vue'

let MessageBoxConstructor = Vue.extend(messageBox);
let instance;

const MessageBox = function(options) {
	options = options || {};
	if (typeof options === 'string') {
		options = {
			message: options
		};
	}
	instance = new MessageBoxConstructor({
		data: options,
	});
	instance.$mount();
	document.body.appendChild(instance.$el);
	//return instance;
	return new Promise((resolve, reject) => {
		console.log(resolve, reject);
	});
};


MessageBox.alert = (message, title, options) => {
	if (typeof title === 'object') {
		options = title;
		title = '';
	} else if (title === undefined) {
		title = '';
	}
	return MessageBox({
		title: title,
		message: message,
		$type: 'alert',
		closeOnPressEscape: false,
		closeOnClickModal: false,
		...options,
	});
};

MessageBox.confirm = (message, title, options) => {
	if (typeof title === 'object') {
		options = title;
		title = '';
	} else if (title === undefined) {
		title = '';
	}
	return MessageBox({
		title: title,
		message: message,
		type_a: 'confirm',
		showCancelButton: true,
		...options,
	});
};

MessageBox.prompt = (message, title, options) => {
	if (typeof title === 'object') {
		options = title;
		title = '';
	} else if (title === undefined) {
		title = '';
	}
	return MessageBox({
		title: title,
		message: message,
		type_a: 'prompt',
		showCancelButton: true,
		...options,
	});
};

export default MessageBox